package com.lanhu.designpattern.singleton.threadlocal;

/**
 * author:zhangzg
 * date:2020/11/2 7:10
 * 线程安全的，线程间的单例，同一个线程拿到的是一个单例，多线程之间拿到的不通
 */
public class SingletonTheadLocal {

    private SingletonTheadLocal (){}

    public static final ThreadLocal<SingletonTheadLocal> threadLocalSingleton = new ThreadLocal<SingletonTheadLocal>(){
        @Override
        protected SingletonTheadLocal initialValue() {
            return new SingletonTheadLocal();
        }
    };

    public static SingletonTheadLocal getInstance(){
        return threadLocalSingleton.get();
    }
}
